package com.googlecode.npgame.simulation;

/**
 * @author Josh (joshbruning)
 */
public class Element {

  private final ElementType elementType;
  private final int maxVolume;
  private final int drainRate;

  private int volume;

  public Element(ElementType elementType, int maxVolume, int drainRate) {
    this.elementType = elementType;
    this.maxVolume = maxVolume;
    this.drainRate = drainRate;
    // Packets start out full.
    this.volume = this.maxVolume;
  }

  public ElementType getElementType() {
    return this.elementType;
  }

  public int getMaxVolume() {
    return this.maxVolume;
  }

  public int getDrainRate() {
    return this.drainRate;
  }

  public int getVolume() {
    return this.volume;
  }

  public boolean isEmpty() {
    return this.volume == 0;
  }

  /**
   * @param timeElapsed
   *          elapsed time since the last call in milliseconds
   */
  public void drain(int timeElapsed) {
    this.volume = Math.max(0, this.volume - timeElapsed * drainRate);
  }
}
